package com.gk.study.controller;


import com.gk.study.service.TeacherService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;

@RestController
@RequestMapping("/teacher/finance")
public class FinanceController {
    private final TeacherService teacherService;

    @Autowired
    public FinanceController(TeacherService teacherService) {
        this.teacherService = teacherService;
    }

    @GetMapping("/total-income")
    public ResponseEntity<?> getTotalIncome(@RequestParam Long userId) {
        try {
            if (userId == null) {
                return ResponseEntity.badRequest().body("用户ID不能为空");
            }
            BigDecimal totalIncome = teacherService.getTotalIncome(userId);
            return ResponseEntity.ok(totalIncome);
        } catch (Exception e) {
            return ResponseEntity.internalServerError().body("服务器异常");
        }
    }
}